package cn.qyd.concurrentcollection;

import java.util.*;
import java.util.concurrent.*;

/**
 * @author 邱运铎
 * @date 2024-03-21 17:07
 */
public class BlockQueueDemo {
    BlockingQueue blockingQueue = new ArrayBlockingQueue(10);
    LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue();
    DelayQueue delayQueue = new DelayQueue();
    PriorityBlockingQueue priorityBlockingQueue = new PriorityBlockingQueue();
    SynchronousQueue synchronousQueue = new SynchronousQueue();

    CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList();
    CopyOnWriteArraySet copyOnWriteArraySet = new CopyOnWriteArraySet();

    public static void main(String[] args) {
        HashMap<Integer,Integer> hashMap = new HashMap();
        Object compute = hashMap.compute(1, (k,v)->   v=9 );
        System.out.println(compute);
        System.out.println(hashMap);
        Integer integer = hashMap.computeIfAbsent(1, v -> v = 3);
        System.out.println(integer);
        System.out.println(hashMap);
        Integer integer1 = hashMap.computeIfAbsent(2, v -> 98);
        System.out.println(integer1);
        System.out.println(hashMap);
        Object o = hashMap.computeIfPresent(1, (k, y) -> y = 2);
        System.out.println(o);
        System.out.println(hashMap);
        Object o1 = hashMap.computeIfPresent(5, (k, y) -> y = 12);
        System.out.println(o1);
        System.out.println(hashMap);
        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("hello");
        Iterator<String> iterator = hashSet.iterator();
        int i = 0;
        while (iterator.hasNext()) {
            iterator.next();
            System.out.println(i++);
        }

    }
}
